﻿import 'dart:io';

void main() {
  const int minTemp = 15;
  const int maxTemp = 30;

  bool lightsOn = false;
  int thermostatTemp = 20;
  bool securityArmed = false;

  print('Welcome to the Smart Home System!');

  while (true) {
    print('\nPlease choose an action:');
    print('1. Toggle lights');
    print('2. Set thermostat temperature');
    print('3. Arm/disarm security system');
    print('4. View system status');
    print('5. Exit');

    stdout.write('\nEnter your choice: ');
    String? choice = stdin.readLineSync();

    if (choice == null) {
      print('Invalid input. Please try again.');
      continue;
    }

    if (choice == '5') {
      print('Exiting the system. Goodbye!');
      break;
    }

    switch (choice) {
      case '1':
        lightsOn = !lightsOn;
        print('Lights are now ${lightsOn ? "ON" : "OFF"}.');
        break;

      case '2':
        while (true) {
          stdout.write('Set thermostat temperature ($minTemp°C - $maxTemp°C): ');
          String? tempInput = stdin.readLineSync();

          if (tempInput == null) {
            print('Invalid input. Please enter a number.');
            continue;
          }

          int? temp = int.tryParse(tempInput);

          if (temp == null || temp < minTemp || temp > maxTemp) {
            print('Temperature must be between $minTemp°C and $maxTemp°C.');
            continue;
          }

          thermostatTemp = temp;
          print('Thermostat set to $thermostatTemp°C.');
          break;
        }
        break;

      case '3':
        securityArmed = !securityArmed;
        print('Security system is now ${securityArmed ? "ARMED" : "DISARMED"}.');
        break;

      case '4':
        print('System Status:');
        print('- Lights: ${lightsOn ? "ON" : "OFF"}');

        // FizzBuzz-like for thermostat temperature:
        String dayDescription = '';
        if (thermostatTemp % 3 == 0 && thermostatTemp % 5 == 0) {
          dayDescription = 'Perfect Day';
        } else if (thermostatTemp % 3 == 0) {
          dayDescription = 'Cool Day';
        } else if (thermostatTemp % 5 == 0) {
          dayDescription = 'Warm Day';
        }

        print('- Thermostat: $thermostatTemp°C${dayDescription.isNotEmpty ? " - $dayDescription" : ""}');
        print('- Security System: ${securityArmed ? "ARMED" : "DISARMED"}');
        break;

      default:
        print('Invalid choice. Please select a valid option.');
    }
  }
}

